﻿#include "clockitemfragment.h"
#include "ui_clockitemfragment.h"
#include "getclockeventdialog.h"
ClockItemFragment::ClockItemFragment(Clock clock,QWidget *parent) :
    QWidget(parent),
    ui(new Ui::ClockItemFragment)
{
    ui->setupUi(this);
    this->clock = clock;
    ui->label_name->setText(clock.getName());
    ui->label_desc->setText(clock.getDescription());
    ui->label_time->setText(clock.getTime().toString("HH:mm"));
    QString rep = "";
    if(clock.getRepeat()&ONCE)rep = tr("Once");
    else{
        if(clock.getRepeat()&MON)rep+=tr("Monday\n");
        if(clock.getRepeat()&TUE)rep+=tr("Tuesday\n");
        if(clock.getRepeat()&WED)rep+=tr("Wednesday\n");
        if(clock.getRepeat()&THU)rep+=tr("Thursday\n");
        if(clock.getRepeat()&FRI)rep+=tr("Friday\n");
        if(clock.getRepeat()&SAT)rep+=tr("Saturday\n");
        if(clock.getRepeat()&SUN)rep+=tr("Sunday\n");
    }
    ui->label_repeat->setText(rep);
}

ClockItemFragment::~ClockItemFragment()
{
    delete ui;
}

bool ClockItemFragment::isChosen()
{
    return chosen;
}

void ClockItemFragment::on_pushButton_edit_clicked()
{
    Clock clock = GetClockEventDialog::getClock(this->clock);
    ui->label_name->setText(clock.getName());
    ui->label_desc->setText(clock.getDescription());
    ui->label_time->setText(clock.getTime().toString("HH:mm"));
}

void ClockItemFragment::on_checkBox_stateChanged(int arg1)
{
    this->chosen = arg1;
}

Clock ClockItemFragment::getClock()
{
    return this->clock;
}
